package com.open.harmony.business.mapper;

import com.open.harmony.business.entity.OrderItem;
import io.swagger.models.auth.In;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Service;

import java.util.List;


/**
 * 订单详情
 *
 */
@Mapper
public interface OrderItemMapper {


    List<OrderItem> findAll(Integer userId);

    @Select("select sum(product_num) from order_product where order_id is null and product_id = #{productId} and user_id = #{userId}")
    Integer findByProduct(Integer userId, Integer productId);

    @Insert("insert into order_product(product_id, user_id, product_num) values(#{productId}, #{userId}, #{num})")
    Integer addItem(Integer userId, Integer productId, Double num);

    @Delete("delete from order_product where order_id is null and user_id = #{userId} and product_id = #{productId}")
    Integer delete(Integer userId, Integer productId);

    @Delete("delete from order_product where order_id is null and user_id = #{userId}")
    Integer deleteAll(Integer userId);

    @Update("update order_product set product_num = #{num} where order_id is null and user_id = #{userId} and product_id = #{productId}")
    Integer updateNum(Integer userId, Integer productId, Double num);

    @Insert("insert into `order`(order_store_id, order_status, order_time, order_price) values (#{userId}, 0, now(), #{totalPrice});")
    Integer insertOrder(Integer userId, Double totalPrice);

    Double getShopTotalPrice(Integer userId);

    @Update("update order_product set order_id = (SELECT MAX(order_id) as numId FROM `order`) where order_id is null and user_id = #{userId};")
    Integer updateOrderItem(Integer userId);
}
